package com.homework.test2;

import java.util.Scanner;

public class Demo3 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("从键盘输入整数，进行猜数字");
        int num = (int)(Math.random()*(100+1-1)) + 1;
        int count = 0;
        while (true){
            int i = input.nextInt();
            if (i<0){
                System.err.println("数据不合法");
                return;
            }
            count++;
            if (i<num){
                System.out.println("小了");
            }else if (i>num){
                System.out.println("大了");
            }else {
                System.out.println("猜对了");
                break;
            }
        }
        System.out.println("猜了"+count+"次");
    }
}
